/* Athena Pierce
   Made by monsoon2004
   Remade by Buya
*/

void npc(Player @player, NPC @npc) {
	int state = npc.getState();
	if(state == 0) {
		if(player.getJob() == 0) {
			if(player.getLevel() >= 10) {
				npc.addText("Would you like to become an Archer?");
				npc.sendYesNo();
			}
			else{
				npc.addText("You need to train more. Don't think being the Bowman is a walk in the park...");
				npc.sendOK();
				npc.end();
			}
		}
		else if(player.getJob() == 300 && player.getLevel() >= 30) {
			if(player.getItemAmount(4031010) == 0) {
				if(player.getItemAmount(4031012) > 0) {
					npc.addText("I knew the test wouldn't be a problem for you. Are you ready to choose your next path?");
					npc.sendYesNo();
				}
				else{
					npc.addText("You have improved significantly. Would you like to take the second job test?");
					npc.sendYesNo();
				}
			}
			else{
				npc.addText("Please come back after you have passed the test.");
				npc.sendOK();
				npc.end();
			}
		}
		else{
			npc.addText("How goes your training?");
			npc.sendOK();
			npc.end();
		}
	}
	else if(state == 1) {
		if(npc.getSelected() == YES) {
			if(player.getJob() == 0) {
				player.setJob(300);
				player.giveItem(1452051, 1);
                                player.giveItem(2060000, 6000);
                                player.setMaxHp(player.getMaxHp() + (100 + random(50)));
                                player.setMaxMp(player.getMaxMp() + (25 + random(25)));
                                player.setStr(4);
			        player.setDex(25);
			        player.setInt(4);
			        player.setLuk(4);
                                player.setAp((player.getLevel() - 1) * 5 - 12);
                                player.setSp((player.getLevel() - 10) * 3 + 1);
                                npc.addText("You are now an Archer.");
				npc.sendOK();
				npc.end();
			}
			else if(player.getJob() == 300) {
					if(player.getItemAmount(4031012) == 1) {
						npc.addText("Choose your path. \r\n#L0#Hunter#l\r\n#L1#Crossbowman#l");
						npc.sendSimple();
					}
					else{
						player.giveItem(4031010, 1);
						npc.addText("Very well, I will give you my recommendation letter. Take it to my assistant and she will give you your next task.");
						npc.sendOK();
						npc.end();
					}
			}
		}
		else{
			npc.addText("Hmm.");
			npc.sendOK();
			npc.end();
		}
	}
	else if(state == 2) {
                if (player.getSp() > ((player.getLevel() - 30) * 3)) {
			npc.addText("Hmmm...you have too much SP...you can't make the 2nd job advancement with that many ");
			npc.addText("SP in store. Use more SP on the skills on the 1st level and then come back.");
			npc.sendNext();
                        npc.end();
                        return;
                }
		int type = npc.getSelected();
		npc.setVariable("type", type);
		if(type == 0) {
			player.setJob(310);
			player.setSp(player.getSp() + 1);
                        player.giveItem(4031012, -1);
                        player.setMaxHp(player.getMaxHp() + (300 + random(50)));
                        player.setMaxMp(player.getMaxMp() + (150 + random(50)));
			npc.addText("You are now a Hunter, nothing escapes your bow.");
			npc.sendOK();
			npc.end();
		}
		else if(type == 1) {
			player.setJob(320);
			player.setSp(player.getSp() + 1);
                        player.giveItem(4031012, -1);
                        player.setMaxHp(player.getMaxHp() + (300 + random(50)));
                        player.setMaxMp(player.getMaxMp() + (150 + random(50)));
			npc.addText("You are now a Crossbowman, extremely accurate and deadly.");
			npc.sendOK();
			npc.end();
		}
	}
}